using UnityEngine;
using UnityEngine.UI;

public delegate void SelectEvent(int id);
public class SelectID : MonoBehaviour
{
    public Text txtID; //显示ID
    public int idMax = 20;
    public int id = 1;
    public int ID
    {
        get { return id; } //最大ID
        set
        {
            if (value > idMax) value = 1;
            if (value < 1) value = idMax;
            id = value;
            txtID.text = value.ToString();
            selEvent?.Invoke(id);
        }
    }
    public event SelectEvent selEvent;
    public Button btnAdd; //增加按钮
    public Button btnSub; //减少按钮
    void Start()
    {
        btnAdd.onClick.AddListener(onBtnAdd);
        btnSub.onClick.AddListener(onBtnSub);
    }
    /// <summary>监听选择ID事件</summary>
    /// <param name="callback"> 回调参数:int ID </param>
    public void onSelect(SelectEvent callback)
    {
        selEvent += callback;
    }

    void onBtnAdd()
    {
        ID++;
    }

    void onBtnSub()
    {
        ID--;
    }
}